<?php

namespace api\controller;

use common\service\StepCategoryMonthReportService;
use common\controller\VerifyController;
use think\Exception;
use think\Response;
use think\Request;

class StepCategoryMonthReportController extends VerifyController
{

    /** @var StepCategoryMonthReportService $service */
    private $service;

    public function __construct()
    {
        parent::__construct();
        $this->service = StepCategoryMonthReportService::getInstance();
    }

    /**
     * 环节月度报表环节列表
     * @param Request $request
     * @return Response
     * @throws Exception
     */
    public function stepCategoryList(Request $request)
    {
        $param = $request->param()['param'];
        $param['only_abnormal'] = $param['only_abnormal'] ?? 'no';
        $dateParam = $param;
        $res = $this->service->stepCategoryList($param['project_id'], $dateParam, $param['only_abnormal'] === 'yes');
        return json(success_response('OK', $res));
    }

    /**
     * 报表详情
     * @param Request $request
     * @return Response
     */
    public function detail(Request $request)
    {
        $param = $request->param()['param'];
        $dateParam = $param;
        $res = $this->service->detail($param['project_id'], $dateParam, $param['step_category_id_list']);
        return json(success_response('OK', $res));
    }

    /**
     * 获取交付列表
     * @param \think\Request $request
     * @return \think\Response
     */
    public function getDeliveryList(Request $request)
    {
        $param = $request->param()['param'];
        $res = $this->service->getDeliveryList($param);
        return json(success_response('OK', $res));
    }

    /**
     * 获取工单问题列表
     * @param \think\Request $request
     * @return \think\Response
     */
    public function getWorkOrderProblemList(Request $request){
        $param = $request->param()['param'];
        $res = $this->service->getWorkOrderProblemList($param);
        return json(success_response('OK', $res));
    }

    /**
     * 获取环节工单统计
     * @param \think\Request $request
     * @return \think\Response
     */
    public function getWorkOrderProblemCount(Request $request){
        $param = $request->param()['param'];
        $res = $this->service->getWorkOrderProblemCount($param);
        return json(success_response('OK', $res));
    }

}
